﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTQT.TTQT_Code;

public partial class RSS : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string channelId = Request.QueryString["channelId"];
        string url = Request.Url.ToString().ToLower();
        url = url.Substring(0, url.IndexOf("rss.aspx"));
        channelId = TTQTCommon.isNull(channelId, "-1");
        TinTucDAO dao = new TinTucDAO();

        NewsRSS rss = new NewsRSS();

        NewsRSS.RssChannel channel = new NewsRSS.RssChannel();
        channel.Title = "RSS tin tức parkerpen.com.vn";
        channel.Link = "#";
        if (channelId.Equals("-1"))
        {
            channel.Description = "Tin tức chung";
        }
        else
        {
            //Lay thong tin ve channel

            DataTable tb = dao.tintuc_nhom_getByID(channelId);
            if (tb != null)
            {
                if (tb.Rows.Count > 0)
                {
                    channel.Description = tb.Rows[0]["name"].ToString();
                }
            }
        }
        rss.AddRssChannel(channel);

        //Lay cac tin tuc theo channelId
        DataTable tin = new DataTable();
        tin = dao.tinTuc_GetTopForRSS(channelId, "-1");
        if (tin != null)
        {
            if (tin.Rows.Count > 0)
            {
                foreach (DataRow r in tin.Rows)
                {
                    NewsRSS.RssItem item = new NewsRSS.RssItem();

                    item.Title = r["title"].ToString();

                    item.Link = url + "NewsDetail.aspx?newsid=" + r["NewsId"].ToString();

                    item.Description = r["summary"].ToString();

                    rss.AddRssItem(item);
                }
            }
        }



        Response.Clear();

        Response.ContentType = "text/xml";

        Response.Write(rss.RssDocument);

        Response.End();

    }
}
